package br.org.etec.dotcao.dao.jpa;

import java.util.Collections;
import java.util.List;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import br.org.etec.dotcao.dao.AnimalDao;
import br.org.etec.dotcao.model.Animal;
import br.org.etec.dotcao.model.AnimalStatus;

public class AnimalDaoImpl extends JPAImpl<Animal> implements AnimalDao{

	public AnimalDaoImpl() {
		super(Animal.class);
	}

	@Override
	public List<Animal> all(AnimalStatus status) {
		TypedQuery<Animal> query = em.createNamedQuery("selectByStatus", Animal.class);
		query.setParameter("status", status);
		
		try {
			return query.getResultList();
		} catch (NoResultException e) {
			return Collections.emptyList();
		}
	}

}
